import Vue from 'vue'

function makeUri(processName, devId, entry) {
  return `/dev/${processName}/${entry}`
}

function makeApiUri(processName, devId, entry) {
  return `/api/${processName}/${entry}`
}

var hostname = ''

export function setHostname(val) {
  hostname = val
}

export function getUrlPrefix() {
  return `http://${hostname}:7080`
}

export function http(uri, method, data, {timeout = 10000, headers = {}, upload = {}} = {}) {
  var options = {
    url: getUrlPrefix() + encodeURI(uri),
    method: method,
    timeout: timeout, 
    data: data,
    headers: headers,
    upload: upload,
    xhr: {
      withCredentials: true
    }
  }

  return Vue.http(options)
}

import {ProcessApi, StorageApi, RestApi} from 'libs/api.js'

export var multimediaApi = new ProcessApi(http, 'multimedia', 0, makeUri)

